package com.ym.pms.service.impl;

import com.ym.pms.dao.UserMapper;
import com.ym.pms.model.Contract;
import com.ym.pms.dao.ContractMapper;
import com.ym.pms.model.SysUser;
import com.ym.pms.model.User;
import com.ym.pms.service.ContractServices;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ym.pms.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lmt
 * @since 2020-12-23
 */
@Service
public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> implements ContractServices {
    @Autowired
    private ContractMapper contractMapper;

    @Override
    public void deleteInfo(Integer contractId) {
        contractMapper.deleteInfo(contractId);
    }

    @Override
    public List<Contract> queryAll() {
        return contractMapper.queryAll();
    }

    @Override
    public void updateInfo(Integer id, String coRFT) {
        contractMapper.updateInfo(id,coRFT,new Date());
    }

    @Override
    public Contract queryOne(Integer id) {
        return contractMapper.queryOne(id);
    }

    @Override
    public List<Contract> search(Contract contract) {
        return contractMapper.search(contract);
    }

    @Override
    public void saveInfo(Integer id, String coPBName, String coPBPNo) {
        contractMapper.saveInfo(id,coPBName,coPBPNo);
    }

    @Override
    public void addInitInfo(Contract contract) {
        contractMapper.addInitInfo(contract);
    }

    @Override
    public void addPhoto(Integer id, String path) {
        contractMapper.addPhoto(id,path);
    }

    @Override
    //@Scheduled(fixedRate = 5000)//每5秒执行一次
    @Scheduled(cron = "0 0 0 * * ?") //每天0点执行一次
    public void compareTime() {
        List<Contract> contractList=contractMapper.queryAll();
        for (Contract contract:contractList){
            if (new Date().compareTo(contract.getCoMtime())>=0){
                contractMapper.updateStatus(contract.getCoId());
            }
        }
    }

}
